package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-10-22
 * Time：11:56
 */
public class FindOperation implements IOperation{
    public void work(BookList bookList) {
        System.out.println("查找图书");
        System.out.println("请输入书名：");
        Scanner scan = new Scanner(System.in);
        String name = scan.nextLine();

        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getPos(i);
            if (book.getName().equals(name)) {
                System.out.println("找到此书，信息如下：");
                System.out.println(book);
                return;
            }
        }
        System.out.println("查无此书！");
    }
}
